pandas 1.4.2

NotesParametersReturns
f(self, other, axis='columns', level=None, fill_value=None)

Equivalent to dataframe / other , but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rtruediv .

Among flexible wrappers (:None:None:`add`, :None:None:`sub`, :None:None:`mul`, :None:None:`div`, :None:None:`mod`, :None:None:`pow`) to arithmetic operators: :None:None:`+`, :None:None:`-`, :None:None:`*`, :None:None:`/`, :None:None:`//`, :None:None:`%`, :None:None:`**`.

Notes

Mismatched indices will be unioned together.

Parameters

other : scalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

axis : {0 or 'index', 1 or 'columns'}

Whether to compare by the index (0 or 'index') or columns (1 or 'columns'). For Series input, axis to match Series index on.

level : int or label

Broadcast across a level, matching Index values on the passed MultiIndex level.

fill_value : float or None, default None

Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.

Returns

DataFrame

Result of the arithmetic operation.

Get Floating division of dataframe and other, element-wise (binary operator :None:None:`truediv`).

See Also

DataFrame.add

Add DataFrames.

DataFrame.div

Divide DataFrames (float division).

DataFrame.floordiv

Divide DataFrames (integer division).

DataFrame.mod

Calculate modulo (remainder after division).

DataFrame.mul

Multiply DataFrames.

DataFrame.pow

Calculate exponential power.

DataFrame.sub

Subtract DataFrames.

DataFrame.truediv

Divide DataFrames (float division).

Examples

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame({'angles': [0, 3, 4],
...  'degrees': [360, 180, 360]},
...  index=['circle', 'triangle', 'rectangle'])
... df angles degrees circle 0 360 triangle 3 180 rectangle 4 360

Add a scalar with operator version which return the same results.

This example is valid syntax, but we were not able to check execution
>>> df + 1
           angles  degrees
circle          1      361
triangle        4      181
rectangle       5      361
This example is valid syntax, but we were not able to check execution
>>> df.add(1)
           angles  degrees
circle          1      361
triangle        4      181
rectangle       5      361

Divide by constant with reverse version.

This example is valid syntax, but we were not able to check execution
>>> df.div(10)
           angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
This example is valid syntax, but we were not able to check execution
>>> df.rdiv(10)
             angles   degrees
circle          inf  0.027778
triangle   3.333333  0.055556
rectangle  2.500000  0.027778

Subtract a list and Series by axis with operator version.

This example is valid syntax, but we were not able to check execution
>>> df - [1, 2]
           angles  degrees
circle         -1      358
triangle        2      178
rectangle       3      358
This example is valid syntax, but we were not able to check execution
>>> df.sub([1, 2], axis='columns')
           angles  degrees
circle         -1      358
triangle        2      178
rectangle       3      358
This example is valid syntax, but we were not able to check execution
>>> df.sub(pd.Series([1, 1, 1], index=['circle', 'triangle', 'rectangle']),
...  axis='index') angles degrees circle -1 359 triangle 2 179 rectangle 3 359

Multiply a DataFrame of different shape with operator version.

This example is valid syntax, but we were not able to check execution
>>> other = pd.DataFrame({'angles': [0, 3, 4]},
...  index=['circle', 'triangle', 'rectangle'])
... other angles circle 0 triangle 3 rectangle 4
This example is valid syntax, but we were not able to check execution
>>> df * other
           angles  degrees
circle          0      NaN
triangle        9      NaN
rectangle      16      NaN
This example is valid syntax, but we were not able to check execution
>>> df.mul(other, fill_value=0)
           angles  degrees
circle          0      0.0
triangle        9      0.0
rectangle      16      0.0

Divide by a MultiIndex by level.

This example is valid syntax, but we were not able to check execution
>>> df_multindex = pd.DataFrame({'angles': [0, 3, 4, 4, 5, 6],
...  'degrees': [360, 180, 360, 360, 540, 720]},
...  index=[['A', 'A', 'A', 'B', 'B', 'B'],
...  ['circle', 'triangle', 'rectangle',
...  'square', 'pentagon', 'hexagon']])
... df_multindex angles degrees A circle 0 360 triangle 3 180 rectangle 4 360 B square 4 360 pentagon 5 540 hexagon 6 720
This example is valid syntax, but we were not able to check execution
>>> df.div(df_multindex, level=1, fill_value=0)
             angles  degrees
A circle        NaN      1.0
  triangle      1.0      1.0
  rectangle     1.0      1.0
B square        0.0      0.0
  pentagon      0.0      0.0
  hexagon       0.0      0.0
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/ops/__init__.py#418
type: <class 'function'>
Commit: